package com.zhz.mall.portal.controller;

import com.zhz.mall.common.api.CommonResult;
import com.zhz.mall.common.exception.ApiException;
import com.zhz.mall.portal.contant.PayErrorCode;
import com.zhz.mall.portal.modules.oms.service.TradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhouhengzhe
 * @date 2023/2/4
 */
@RestController
@Api("支付控制器")
@RequestMapping("/order")
@Slf4j
public class PayController {

    @Autowired
    private TradeService tradeService;

    /**
     * 生成当面付二维码
     * /order/tradeQrCode
     * orderId:this.orderId,
     * payType:1
     */
    @ApiOperation("支付接口，只实现支付宝支付，微信支付暂未实现")
    @ApiImplicitParams({@ApiImplicitParam(name = "orderId", value = "订单id"),
            @ApiImplicitParam(name = "payType", value = "支付类型1:支付宝2：微信"
                    , allowableValues = "1,2", dataType = "integer")})
    @PostMapping("tradeQrCode")
    public CommonResult<String> tradeQrCode(@RequestParam("orderId") Long orderId,
                                            @RequestParam("payType") Integer payType) {
        if (payType > 2 || payType < 0) {
            throw new ApiException(PayErrorCode.PAY_TYPE_PARAM_ERROR);
        }
        return tradeService.tradeQrCode(orderId, payType);
    }

}
